package com.xbongbong.saas.enums.dictionary;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 报价单状态枚举
 * @author long.rao
 * @version v1.0
 * @date 2019/8/13 14:25
 * @since v1.0
 */
@Getter
public enum QuotationStatusEnum {

    // Bom状态
    IN_QUOTATION("1", "enum.quotationStatus.name.in_quotation", "inQuotation"),


    INVALID("2", "enum.quotationStatus.name.invalid", "disable"),


    CREATED("3", "enum.quotationStatus.name.created", "created"),


    UNKNOWN("404", "enum.quotationStatus.name.unknown", "unknown"),
    ;

    private String code;
    private String name;
    private String attr;

    QuotationStatusEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    /**
     * 获取全部枚举
     */
    public static List<QuotationStatusEnum> getAllEnum() {
        List<QuotationStatusEnum> list = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for (QuotationStatusEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    public static List<JSONObject> getItemPoJoList(String status) {
        List<JSONObject> itemPoJoList = new ArrayList<>();
        List<QuotationStatusEnum> allEnum = getAllEnum();
        allEnum.forEach(item -> {
            JSONObject itemObj = new JSONObject();
            itemObj.put("text", item.getName());
            itemObj.put("value", item.getCode());
            if (Objects.equals(Objects.toString(item.getCode()), status)) {
                itemObj.put("checked", true);
            }
            itemPoJoList.add(itemObj);
        });
        return itemPoJoList;
    }

    public static String getName(String status) {
        JSONObject name = new JSONObject();
        List<QuotationStatusEnum> allEnum = getAllEnum();
        allEnum.forEach(item->{
            if (Objects.equals(Objects.toString(item.getCode()), status)) {
                String name1 = item.getName();
                name.put("status", name1);
            }
        });
        return Objects.toString(name.get("status"), "");
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
